#include <cgic.h>
#include <glib.h>

// 用于文件接收前端请求参数
int cgiMain(){
    char gatewayIp[128];
    char location[256];

    cgiFormString("gatewayIp",gatewayIp,128);
    cgiFormString("location",location,256);

    //用glib把数据保存到ini配置文件
    GKeyFile *file = g_key_file_new();
    g_key_file_load_file(file,"../config/config.ini",G_KEY_FILE_NONE,NULL);
    gchar* path = g_key_file_get_string(file,"confil","deviceInfoPath",NULL);
    

    GKeyFile *keyFile=g_key_file_new();
    g_key_file_set_string(keyFile,"config","gatewayIp",gatewayIp);
    g_key_file_set_string(keyFile,"config","location",location);
    g_key_file_save_to_file(keyFile,path,NULL);
    g_key_file_free(keyFile);


    cgiHeaderContentType("text/html");
	/* Top of the page */
	fprintf(cgiOut, "<HTML><HEAD> <meta charset=\"UTF-8\"> \n");
	fprintf(cgiOut, "<TITLE>cgic 测试</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1>操作成功</H1>\n");
    fprintf(cgiOut,"</BODY></HTML>");

    return 0;
}